package com.spider.silence.job;

import com.spider.silence.downloader.ChengDuWanBaoDownloader;
import com.spider.silence.downloader.SiChuanRenShiDownloader;
import com.spider.silence.pool.ChengDuWanBaoDownloaderPool;
import com.spider.silence.pool.SiChuanRenShiDownloaderPool;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.StatefulJob;

/**
 * Created by admin on 2017/7/6.
 * 成都晚报爬虫定时任务
 */
public class ChengDuWanBaoJob implements StatefulJob {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        ChengDuWanBaoDownloaderPool downloaderPool = ChengDuWanBaoDownloaderPool.getInstance();
        ChengDuWanBaoDownloader downloader = null;
        try {
            downloader = downloaderPool.fetchDownLoader(1000);
            while (true) {
                if(downloader != null) {
                    break;
                } else {
                    downloader = downloaderPool.fetchDownLoader(1000);
                }
            }
            downloader.generateTask();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            if(downloader != null) {
                downloaderPool.releaseDownLoader(downloader);
            }
        }
    }
}
